package com.game.league.task.sub.adapter;

import android.app.Activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.game.base.app.base.BaseAdapter;
import com.game.base.app.callback.ItemOnClick;
import com.game.base.glideV4.ImageLoader;
import com.game.league.R;
import com.game.league.databinding.AdapterTaskAsoBinding;
import com.game.league.task.detail.adapter.TaskTagAdapter;
import com.game.league.task.table.Task;
import com.game.league.util.SkipUtil;

import java.util.ArrayList;

/**
 * Created by Su on 2019/6/7.
 */
public class TaskSimpleAdapter extends BaseAdapter<Task, AdapterTaskAsoBinding> {
    public TaskSimpleAdapter(Activity activity, ItemOnClick itemOnClick) {
        super(activity, itemOnClick);
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.adapter_task_aso;
    }

    @Override
    protected void onBindItem(AdapterTaskAsoBinding binding, Task item, int position) {
        ImageLoader.loadRoundCenterCrop(mActivity, item.getImage(), binding.ivAppLogo);
        binding.tvAppName.setText(item.getTitle());
        binding.btnSubmit.setOnClickListener(v -> SkipUtil.showTaskDetailActivity(mActivity, item));

        // 任务标签
        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        binding.recyclerTag.setLayoutManager(layoutManager);
        TaskTagAdapter tagAdapter = new TaskTagAdapter();
        binding.recyclerTag.setAdapter(tagAdapter);
        tagAdapter.setItems((ArrayList<String>) item.getLabel());
    }
}
